﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace Microsoft.Forums.OfflineStore
{

    /// <summary>
    /// Customizations on the ForumsOfflineStore datacontext
    /// </summary>
    public partial class ForumsOfflineStore
    {
        /// <summary>
        /// A custom implementation of SubmitChanges.  This will catch the concurrency exception and then
        /// automatically merge the results.  
        /// 
        /// It merges by only changing values which have been modified and synchronizes the other values with the
        /// current database values
        /// </summary>
        public void SubmitChangesWithMerge()
        {
            try
            {
                this.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException)
            {
                // Automerge database values for members that client
                // has not modified.
                foreach (ObjectChangeConflict occ in this.ChangeConflicts)
                {
                    occ.Resolve(RefreshMode.KeepChanges);
                }

                // Try to submit again and hopefully we wont have any conflicts
                this.SubmitChangesWithMerge();
            }
        }
    }

    /// <summary>
    /// The type of thread
    /// </summary>
    public enum ThreadType : int
    {
        None = 0,
        Question = 1,
        Bug = 2,
        Comment = 3,
        Suggestion = 4,
    }

    /// <summary>
    /// Type of forum
    /// </summary>
    public enum ForumType : int
    {
        None = 0,
        Forum = 1,
        ModeratorForum = 4,
        PrivateForum = 5,
        ModeratorPostingForum = 6,
    }

    /// <summary>
    /// The type of Post
    /// </summary>
    public enum PostType : int
    {
        None = 0,
        ProposedAnswer = 1,
        Answer = 2,
        Question = 3,
        Bug = 4,
    }

    /// <summary>
    /// The type of Actions
    /// </summary>
    public enum ActionType : int
    {
        Reply,
        NewThread,
        Move,
        Delete,
        Edit,
        MarkAsAnswer,
        UnmarkAsAnswer,
        ProposeAnswer,
        UnProposeAnswer,
        MarkAbusive,
        UnmarkAbusive
    }

     /// <summary>
    /// The status of Actions
    /// </summary>
    public enum ActionStatus : int
    {
        Pending,
        Failed
    }
}
